export enum ResponseType {
    SEND_INIT_DATA = 'send_init_data',
    NEED_INIT_DATA = 'need_init_data',
    SEND_USER_ROLE = 'send_user_role',
    MESSAGE = 'message',
    RECOGNIZE_MESSAGE = 'recognize_message',
    SEND_ELEMENT_DATA = 'send_element_data',
    SEND_CARDTYPE_DATA='send_cardtype_data',
    SEND_ROOM_ROLE='send_room_role',
    SEND_USER_LIST='send_user_list',
}
export default interface responseMessage {
    body: string
    sender: string[]
    type: ResponseType
    recevier: string
    msgId:string
}
function isResponseType(value: any): value is ResponseType {
    return Object.values(ResponseType).includes(value);
}
export function jsonToRes(json: string): responseMessage {
    let jsonObject = JSON.parse(json)
    if (!isResponseType(jsonObject.type)) {
        throw new Error(`Unknown response type: ${jsonObject.type}`);
    }
    return {
        body: jsonObject.body,
        sender: jsonObject.sender,
        type: jsonObject.type,
        recevier: jsonObject.recevier,
        msgId:jsonObject.msgId
    }
}